package com.android.qjpmc.data_module;

public class DataTeamSet {
    DataTeam m_Head = null;

    DataTeam GetHead()
    {
        return m_Head;
    }

    void SetHead(DataTeam Node)
    {
        m_Head = Node;
    }

    DataTeam GetTail()
    {
        DataTeam Head = GetHead();
        DataTeam Next = null;
        if (Head == null)
        {
            return null;
        }
        Next = Head.GetNext();
        while (Next != null)
        {
            Head = Next;
            Next = Head.GetNext();
        }
        return Head;
    }
    public int AppendANode(DataTeam Node)
    {
        DataTeam Tail = GetTail();
        if (Tail == null)
        {
            SetHead(Node);
        }
        else
        {
            Tail.AppendANode(Node);
        }
        return 0;
    }
    public DataTeam GetPwrDevice(int ID)
    {
        DataTeam Device = GetHead();
        while(Device != null)
        {
            if (Device.IsMe(ID) == 1)
            {
                return  Device;
            }
            Device = Device.GetNext();
        }
        return Device;
    }

    //释放设备链表
    public int Release()
    {
        DataTeam Head = GetHead();
        DataTeam TheNode = null;
        DataTeam ToDelNode = null;
        TheNode = Head;
        while(TheNode != null)
        {
            ToDelNode = TheNode;
            TheNode = TheNode.GetNext();
            ToDelNode = null;
        }
        return 1;
    }
    //析构函数
    public void finalize()
    {
        Release();
    }
}
